package diamondRingServlet;

import diamondRingEntity.Admin;
import diamondRingEntity.DiamondRingEntity;
import diamondRingService.impl.AdminServiceImpl;
import org.omg.CORBA.INTERNAL;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/BackUpdateGoodsInfoServlet")
public class BackUpdateGoodsInfoServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码格式
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        response.setCharacterEncoding("utf-8");
        PrintWriter out=response.getWriter();

        AdminServiceImpl adminService = new AdminServiceImpl();
        int count = 0;

        int ID =Integer.parseInt(request.getParameter("ID"));
        System.out.println(ID);
        String goodspath = request.getParameter("goodspath");



        String newPath = goodspath.substring(12,goodspath.length());


        String newPathOne = "images/"+newPath;

        System.out.println(goodspath);


        String series = request.getParameter("series");
        System.out.println(series);
        String style = request.getParameter("style");
        System.out.println(style);
        String texture = request.getParameter("texture");
        System.out.println(texture);
        String shape = request.getParameter("shape");
        System.out.println(shape);
        String type = request.getParameter("type");
        System.out.println(type);
        String colour = request.getParameter("colour");
        System.out.println(colour);
        String carat = request.getParameter("carat");
        System.out.println(carat);
        int diamondPrice = Integer.parseInt(request.getParameter("diamondPrice"));
        System.out.println(diamondPrice);

        DiamondRingEntity diamondRingEntity = new DiamondRingEntity(newPathOne,series,style,texture,shape,type,colour,carat,diamondPrice);

        if (adminService.UpdateGoodsInfo(diamondRingEntity,ID)>0){
            count = 1;
        }else{
            count = -1;
        }
        out.print(count);
        out.flush();
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
